package com.boc.ewr.risk.service.impl;

import com.boc.ewr.bcimp.entity.Pro;
import com.boc.ewr.business.entity.ProPrbsdList;
import com.boc.ewr.risk.entity.IntranetCaFdbk;
import com.boc.ewr.risk.mapper.IntranetCaFdbkMapper;
import com.boc.ewr.risk.service.IIntranetCaFdbkService;
import com.boc.ewr.util.MsgCategoryEnum;
import com.boc.ewr.util.ToUserUtil;
import com.boc.ewr.util.file.enumeration.ProSendStatusEnum;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * @Description: 内网对账数据反馈清单
 * @Author: jeecg-boot
 * @Date: 2023-04-20
 * @Version: V1.0
 */
@Service
public class IntranetCaFdbkServiceImpl extends ServiceImpl<IntranetCaFdbkMapper, IntranetCaFdbk> implements IIntranetCaFdbkService {


    @Autowired
    private ISysBaseAPI sysBaseAPI;

    @Autowired
    IntranetCaFdbkMapper intranetCaFdbkMapper;

    /**
     *每周导入
     * “内网对账数据”
     * “内网对账专用IP及对应摄像头”
     */


    //批量导入
    @Transactional
    public boolean initSaveBatch(Collection<IntranetCaFdbk> entityList, Boolean flag) {
        if (entityList.isEmpty() || entityList.size() == 0) {
            return false;
        }
        //以最后一次导入为准，清空原数据
        if (flag){
            intranetCaFdbkMapper.delete(null);
        }
        // 触发消息推送
        this.sendMsg(entityList);
        //保存数据
        return saveBatch(entityList, DEFAULT_BATCH_SIZE);
    }

    private void sendMsg(Collection<IntranetCaFdbk> entityList) {

        Set<String> orgSet = new HashSet();
        for (IntranetCaFdbk intranetCaFdbk : entityList) {
            orgSet.add(intranetCaFdbk.getOrgNo());
        }

        // 信息推送至网点对账人员
        String toUser = ToUserUtil.genToUser(orgSet);
        if (toUser != null) {
            MessageDTO messageDTO = new MessageDTO(
                    "system",
                    toUser,
                    "内网对账数据反馈",
                    "您有新的内网对账数据反馈任务，请及时查看并完成排查！",
                    MsgCategoryEnum.RISK_CHECK.getIndex());
            sysBaseAPI.sendSysAnnouncement(messageDTO);
        }

    }
}
